import { list, total } from '@/api/xxx'
export default {
  namespaced: true
  ,state: () => ({
    list: []
    , columns: []
    ,total: 0
    ,offset: 0
    ,limit: 10
  })
  ,mutations: {
    SET_LIST(state, payload){
      state.list= payload
    },
    SET_COLUMNS(state, payload){
      state.columns= payload
    }
  }
  ,getters: {
    list: state=>state.list
    ,columns: state=>state.columns
  }
  ,actions: {
    struct({commit}, form){
      return new Promise((resolve, reject) => {
        struct().then(resp =>{
          commit("SET_COLUMNS", resp)
          resolve()
        }).catch(err=>{
          reject(err)
        })
      })
    },
    fetch({commit}, form){
      const { offset, limit } = form
      return new Promise((resolve, reject) => {
        list({offset, limit}).then(resp =>{
          commit("SET_LIST", resp)
          resolve()
        }).catch(err=>{
          reject(err)
        })
      })
    },
    count({commit}, form){
      return new Promise((resolve, reject) => {
        total().then(resp =>{
          commit("SET_TOTAL", resp)
          resolve()
        }).catch(err=>{
          reject(err)
        })
      })
    }
  }
  ,computed: { }
}
